import {BallColorIdx} from "./GameConfig";
import LineGameBallData from "./LineGame/LineGameBallData";


export default class LevelCfgItem
{
    public levelId:number=0;
    public levelType:number=0;
    public diff:number=0;
    public stepLimit:number=0;
    public conditions=[];

    public lineGameBalls:Array<LineGameBallData>=[];

    public parse(conditionObj)
    {
        if(!conditionObj)
        {
            console.error("关卡配置conditionObj为空!");
            return;
        }

        if(conditionObj.hasOwnProperty("step"))
        {
            this.stepLimit=conditionObj.step;
        }
        else
        {
            console.error("关卡配置conditionObj 缺少step属性 !");
        }

        let key=null;
        for(key in conditionObj)
        {
            if(key==="step")
                continue;
            if((key==="r" || key==="g" || key==="b" || key==="o" || key==="p" || key==="c") && conditionObj[key]>0)
            {
                this.conditions.push({c:key, cid:BallColorIdx[key], num:conditionObj[key]});
            }
        }

        //console.log("**** condition="+JSON.stringify(this.conditions));
    }

    public parseLineGame(balls)
    {
        for(let i=0;i<balls.length;i++)
        {
            let data:LineGameBallData=new LineGameBallData();
            data.val=parseInt(balls[i].val);
            data.pos0.set(balls[i].pos0.x, balls[i].pos0.y);
            data.pos1.set(balls[i].pos1.x, balls[i].pos1.y);
            this.lineGameBalls.push(data);
        }
    }
}

